﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public partial class FormWareByWare : System.Windows.Forms.Form
	{
		public FormWareByWare()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.InitUserSetting();
		}

		private void InitUserSetting()
		{
			try
			{
				if (this.userSetting.GetValue("LayWares", "IsByNumber") != "")
				{
					if (this.userSetting.GetValue("LayWares", "IsByNumber") == "True")
					{
						this.cbNumber.Checked = true;
					}
					else
					{
						this.cbNumber.Checked = false;
					}
				}
				if (this.userSetting.GetValue("LayWares", "WareNumber") != "")
				{
					this.nudNumber.Value = Convert.ToDecimal(this.userSetting.GetValue("LayWares", "WareNumber"));
				}
				if (this.userSetting.GetValue("LayWares", "WareOffset") != "")
				{
					this.txtOffset.Text = this.userSetting.GetValue("LayWares", "WareOffset");
				}
				if (this.userSetting.GetValue("LayWares", "WareDistance") != "")
				{
					this.txtDistance.Text = this.userSetting.GetValue("LayWares", "WareDistance");
				}
			}
			catch (Exception)
			{
			}
		}

		private void txtDistance_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.distance = (int)Convert.ToInt16(this.txtDistance.Text);
			}
			catch
			{
			}
		}

		private void txtOffset_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.offset = (int)Convert.ToInt16(this.txtOffset.Text);
			}
			catch
			{
			}
		}

		private void cbNumber_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbNumber.Checked)
			{
				this.nudNumber.Enabled = true;
				this.isByNumber = true;
				return;
			}
			this.nudNumber.Enabled = false;
			this.isByNumber = false;
		}

		private void btn_Confirm_Click(object sender, EventArgs e)
		{
			try
			{
				this.offset = Convert.ToInt32(this.txtOffset.Text);
				this.distance = Convert.ToInt32(this.txtDistance.Text);
				this.wareCount = Convert.ToInt32(this.nudNumber.Value);
				if (this.cbNumber.Checked)
				{
					this.isByNumber = true;
				}
				else
				{
					this.isByNumber = false;
				}
			}
			catch
			{
			}
			this.SetUserData();
			base.DialogResult = DialogResult.OK;
		}

		private void btn_Cancle_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void SetUserData()
		{
			this.userSetting.WriteValue("LayWares", "IsByNumber", this.cbNumber.Checked.ToString());
			this.userSetting.WriteValue("LayWares", "WareNumber", this.nudNumber.Value.ToString());
			this.userSetting.WriteValue("LayWares", "WareOffset", this.txtOffset.Text);
			this.userSetting.WriteValue("LayWares", "WareDistance", this.txtDistance.Text);
		}

		public int distance = 1500;

		public int offset;

		public bool isByNumber;

		public int wareCount = 1;

		private UserSetting userSetting = new UserSetting();
	}
}
